package com.pro.service.imple;

import com.pro.mapper.JsCourseClassMapper;
import com.pro.pojo.JsCourseClass;
import com.pro.pojo.JsSum;
import com.pro.service.JsCourseClassService;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsCourseClassServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2022/1/9 15:52
 * @Author: ZPT
 */
@Service
public class JsCourseClassServiceImple implements JsCourseClassService {
    @Autowired(required = false)
    private JsCourseClassMapper courseClassMapper;

    @Autowired
    private RedisCache redisCache;
    @Override
    public List<JsCourseClass> getCourseClass() {
        List<JsCourseClass> jsCourseClass = redisCache.getCacheList("JsCourseClass");
        if (!jsCourseClass.isEmpty()){
            return jsCourseClass;
        }
        //新建选择分类类型
        JsCourseClass courseClass = new JsCourseClass();
        courseClass.setCategroyId(0);
        courseClass.setTitle("选择分类类型");
        courseClass.setParentId(-1);
        List<JsCourseClass> courseClassList = courseClassMapper.getCourseClass();
        courseClassList.add(courseClass);
        redisCache.setCacheList("JsCourseClass",courseClassList);
        return courseClassList;
    }

    @Override
    public Boolean addCourseClass(JsCourseClass courseClass) {
        courseClass.setCreateDate(new Date());
        Boolean aBoolean = courseClassMapper.addCourseClass(courseClass);
        if (aBoolean){
            redisCache.deleteObject("JsCourseClass");
        }
        return aBoolean;
    }

    @Override
    public Boolean deleteCourseClass(Integer categroyId) {
        Boolean aBoolean = courseClassMapper.deleteCourseClass(categroyId);
        if (aBoolean){
            redisCache.deleteObject("JsCourseClass");
        }
        return aBoolean;
    }

    @Override
    public Boolean updateCourseClass(JsCourseClass courseClass) {
        courseClass.setUpdateDate(new Date());
        Boolean aBoolean = courseClassMapper.updateCourseClass(courseClass);
        if (aBoolean){
            redisCache.deleteObject("JsCourseClass");
        }
        return aBoolean;
    }
    /**
     *
     * @author ZPT
     * @date 2022/1/18 15:19
     * @content :课程分类点赞、分享、收藏、预览量
     */
    @Override
    public List<JsSum> getSum(String field){
        return courseClassMapper.getSum(field);
    }
}
